import { Button, Modal } from "antd"
import FormComponent from "../FormComponent";
import { useMemo, useState } from "react";


interface BFMComponentProps {
    column: any[],
    formData : any [],
    handleTitle : string
}

const ButtonFormModelComponent: React.FC<BFMComponentProps> = ({ column , handleTitle , formData}) => {
    const [isModalOpen, setIsModalOpen] = useState(false);
    const widgets = useMemo(() => {
        return column.filter(item => item['type']).map(item => ({ ...item }));
    }, [column])
    const handleClose = () => {
        setIsModalOpen(false);
    };

    const changeData = (value: any) => {
        console.log(value)
        // 执行改变数据后的操作
    }

    return (
        <>
            <Button type="primary" onClick={() => setIsModalOpen(true)} style={{ margin: 10 }}>{handleTitle}</Button>
            <Modal
                title="编辑"
                open={isModalOpen}
                onCancel={handleClose}
                footer={null}
                key='buttonModal'
            >
                <FormComponent widgets={widgets} data={formData} changeData={changeData} OpenModal={handleClose} />
            </Modal>
        </>
    )

}

export default ButtonFormModelComponent